%% Author: user
%% Created: 2006-8-19
%% Description: TODO: Add desciption to aleph_dht_node
-module(aleph_dht_node).
%%
%% Include files  
%%
   
-include_lib("eunit/include/eunit.hrl").  
-include("aleph_data_interface.hrl").
-import(aleph_dht_hash,[intify/1,new_hash_id/0]).
  
%%
%% Exported Functions
%%
-export([create_node/3,update_last_seen/1,msg_failed/1]).

%%%%%%%%%%%%%%%%%%%% export unit test
-export([update_last_seen_test/0]).

%%%%%%%%%%%%%%%%%%%% public functions
%
%create_node(Id, Host, Port)
%
create_node(Id, Host, Port)->  
    dht_node:create(Id,Port,Host,intify(Id),0,time_stamp(milliseconds)).           

update_last_seen(N)->  
  N({[fails,lastseen],[0,time_stamp(milliseconds)]}).

msg_failed(N)->
   N({fails,N(fails)+1}).


%%%%%%%%%%%%%%%%%%%% private functions


 
%%%%%%%%%%%%%%%%%%%% unit test
update_last_seen_test()->   
    Node=create_node(new_hash_id(),"localhost",20000),  
    %io:format("Node is ~p",[Node]),
    timer:sleep(10),    
    T=Node(lastseen),
    Node2=update_last_seen(Node),
    %%?log("T=~p,Node2.lastseen=~p,diff=~p,diff2=~p",[T,lastseen(Node2),T-lastseen(Node2),timer:now_diff(N1,N2)]),
    ?match(true,(T=<Node2(lastseen))).

    



    